#include "dbfabric.h"

DbFabric::DbFabric()
{
}

QSharedPointer<QSqlRelationalTableModelWithReconnection> DbFabric::createPolygonModel()
{
    QSharedPointer<QSqlRelationalTableModelWithReconnection> model = QSharedPointer<QSqlRelationalTableModelWithReconnection>(new QSqlRelationalTableModelWithReconnection);
    model->setTable("Polygon");
    model->setRelation(POLYGON_MODEL_ID_TYPE, QSqlRelation("MeasurementType", "idMeasurementType", "type"));
    return model;
}

QSharedPointer<QSqlRelationalTableModelWithReconnection> DbFabric::createGeneratorLoopModel()
{
    QSharedPointer<QSqlRelationalTableModelWithReconnection> model = QSharedPointer<QSqlRelationalTableModelWithReconnection>(new QSqlRelationalTableModelWithReconnection);
    model->setTable("GeneratorLoop");
    model->setRelation(LOOP_MODEL_ID_POLYGON, QSqlRelation("Polygon", "idPolygon", "description"));
    model->setRelation(LOOP_MODEL_ID_LOOP_FORM, QSqlRelation("LoopForm", "idLoopForm", "form"));
    return model;
}

QSharedPointer<QSqlRelationalTableModelWithReconnection> DbFabric::createPicketModel()
{
    QSharedPointer<QSqlRelationalTableModelWithReconnection> model = QSharedPointer<QSqlRelationalTableModelWithReconnection>(new QSqlRelationalTableModelWithReconnection);
    model->setTable("Picket");
    model->setRelation(PICKET_MODEL_ID_LOOP, QSqlRelation("GeneratorLoop", "idGeneratorLoop", "idGeneratorLoop"));
    //model->setRelation(PICKET_MODEL_ID_EMF, QSqlRelation("Emf", "idEmf", "idEmf"));
    return model;
}

QSharedPointer<QSqlRelationalTableModelWithReconnection> DbFabric::createEmfModel()
{
    QSharedPointer<QSqlRelationalTableModelWithReconnection> model = QSharedPointer<QSqlRelationalTableModelWithReconnection>(new QSqlRelationalTableModelWithReconnection);
    model->setTable("Emf");
    return model;
}
